package com.css.crm.listener;

import java.util.Map;

import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

import com.css.crm.utility.ConstantUtil;

public class OnPageLoadListener implements PhaseListener {

	private static final long serialVersionUID = -6648737696427976101L;

	public PhaseId getPhaseId() {
		return PhaseId.RESTORE_VIEW;
	}

	public void beforePhase(PhaseEvent event) {

		FacesContext context = event.getFacesContext();
		HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

		Map<String, String> params = context.getExternalContext().getRequestParameterMap();
		String funcId = (String) params.get(ConstantUtil.PARAM_FUNC_ID);

		if (StringUtils.isNotEmpty(funcId)) {
			request.getSession().removeAttribute("createCustomerBean");
			request.getSession().removeAttribute("updateCustomerBean");
		}

		HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
		response.addHeader("X-UA-Compatible", "IE=EmulateIE8");
	}

	public void afterPhase(PhaseEvent event) {

	}
}
